/**
 * Created by smzhang on 2015/11/4.
 */


function post(url,params) {
    	var temp = document.createElement("form");
    	temp.action = url;
    	temp.method = "post";
    	temp.style.display = "none";
    	for (var x in params) {
    	var opt = document.createElement("textarea");
    	opt.name = x;
    	opt.value = params[x];
    	temp.appendChild(opt);
    	}
    	document.body.appendChild(temp);
    	temp.submit();
    	return temp;
    }
function GetDateStr(AddDayCount) {
    var dd = new Date();
    dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
//	    var y = dd.getFullYear();
    var m = dd.getMonth()+1;//获取当前月份的日期
    var d = dd.getDate();
    return m+"-"+d;
}
function getNowDateStr(){
	var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
}
function getNowDateAfterStr(AddDayCount){
	var date = new Date();
    var seperator1 = "-";
    date.setDate(date.getDate()+AddDayCount);//获取AddDayCount天后的日期
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
}
$(function () {
    /**
     * 查询条件显示或隐藏
     */
    $(".collapse-link").click(function () {
        var d = $(".panel-body:first").hasClass("d-n");
        if (d) {
            $(".panel-body:first").removeClass("d-n");
        } else {
            $(".panel-body:first").addClass("d-n");
        }
        $(".collapse-link").removeClass("d-n");
        $(this).addClass("d-n");
    });


});

function getPageSize() {

    var winW, winH;
    if(window.innerHeight) {// all except IE
        winW = window.innerWidth;
        winH = window.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {// IE 6 Strict Mode
        winW = document.documentElement.clientWidth;
        winH = document.documentElement.clientHeight;
    } else if (document.body) { // other
        winW = document.body.clientWidth;
        winH = document.body.clientHeight;
    }  // for small pages with total size less then the viewport
    
    return {WinW:winW, WinH:winH};
}

function doResize(w,h) {
    var ss = getPageSize();
    if(!w) w = 10;   //默认，可根据项目实际情况调整宽度
    if(!h) h = 230; //默认，可根据项目实际情况调整高度
    var jqGridHeight = $("#jqGrid").height()+10;
    var setHeight = ss.WinH-h;
    if(jqGridHeight<setHeight){
    	setHeight = jqGridHeight;
    }
    jQuery("#jqGrid").jqGrid('setGridHeight', setHeight);
}
function StringBuffer(){ 
	this.content = new Array; 
} 
StringBuffer.prototype.append = function(str){ 
	this.content.push(str); 
} 
StringBuffer.prototype.toString = function(){ 
	return this.content.join(''); 
}

//str1 现在要增加的字符串,str2 已存在的字符串,取出str1有，str2无的数据
function addNoRepeat(str1,str2) {
	if(str1 == ''){
		return str2;
	}
	var sb = new StringBuffer("");
	if(str2 == ''){
		sb.append(",");
		sb.append(str1);
		sb.append(",");
		return sb.toString();
	}
	var agtcodes = str1.split(",");
	for (var i = 0; i < agtcodes.length; i++) {
		if (str2.indexOf(","+agtcodes[i]+",") ==-1) {
			sb.append(agtcodes[i]);
			sb.append(",");
		}
	}
	return sb.toString();
}
//str1 ,str2 取交集
function intersection(str1,str2) {
	if(!str1 || !str2){
		return '';
	}
	var arr = new Array;
	var arrStr1 = str1.split(",");
	for (var i = 0; i < arrStr1.length; i++) {
		if (str2.indexOf(","+arrStr1[i]+",") !=-1) {
			arr.push(arrStr1[i]);
		}
	}
	return arr;
}
	 //str1 现在要减去的字符串,str2 已存在的字符串
function offNoRepeat(str1, str2) {
	if (str1 == '') {
		return str2;
	}
	if(str2 == ''){
		return "";
	}
	var allStr1 = ","+str1+",";
	var beforeString = str2.substring(1,str2.length-1);
	var beforeArr = beforeString.split(",");
	var sb = new StringBuffer("");
	for (var i = 0; i < beforeArr.length; i++) {
		if (allStr1.indexOf(","+beforeArr[i]+",")==-1) {
			if (sb.toString() == '') {
				sb.append(",");
			}
			sb.append(beforeArr[i]);
			sb.append(",");
		}
	}
	return sb.toString();
}
function clearNoNum(obj)
{
    //先把非数字的都替换掉，除了数字和.
    obj.value = obj.value.replace(/[^\d.]/g,"");
    //必须保证第一个为数字而不是.
    obj.value = obj.value.replace(/^\./g,"");
    //保证只有出现一个.而没有多个.
    obj.value = obj.value.replace(/\.{2,}/g,".");
    //保证.只出现一次，而不能出现两次以上
}
function lost(obj)
{
	var f = obj.value;  
    if (isNaN(f)) {    
        return false;    
    }    
    obj.value=getNum(f); 
}
function getNum(f){
    
    var f = Math.round(f*100)/100;    
    var s = f.toString();    
    var rs = s.indexOf('.');    
    if (rs < 0) {    
        rs = s.length;    
        s += '.';    
    }    
    while (s.length <= rs + 2) {    
        s += '0';    
    }    
    return s;
}

function StringBuffer(){ 
	this.content = new Array; 
} 
StringBuffer.prototype.append = function(str){ 
	this.content.push(str); 
} 
StringBuffer.prototype.toString = function(){ 
	return this.content.join(''); 
}